package com.gonsin.gnews.annotations.configuration;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.gonsin.i18n.logic.T;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class ConfigViewModel {

    /**
     * 设置的标题
     */
    private String platformName;


    /**
     * 每行设置参数
     */
    private List<FieldItemModel> fieldItem;


    /**
     * 标注配置的类
     */
    @JsonIgnore
    private Class configClass;

    /**
     * 将ViewModel复制一份，但是每行的字段名字，使用T.t 进行翻译
     * @return
     */
    public ConfigViewModel tClone() {
        ConfigViewModel viewModel = new ConfigViewModel();
        viewModel.setConfigClass(this.configClass);
        viewModel.setPlatformName(this.platformName);
        List<FieldItemModel> items = new ArrayList<>();
        for(FieldItemModel item : this.fieldItem){
            FieldItemModel clone = new FieldItemModel();
            clone.setFieldName(item.getFieldName());
            clone.setFieldType(item.getFieldType());
            clone.setPlaceholder(T.t(item.getPlaceholder()));
            clone.setValue(item.getValue());
            clone.setLabelText(T.t(item.getLabelText()));
            items.add(clone);
        }
        viewModel.setFieldItem(items);
        return viewModel;
    }
}
